package de.baumann.browser.activitys.hash

import android.app.Activity
import android.view.Menu
import android.view.MenuItem
import android.view.View
import de.baumann.browser.R
import de.baumann.browser.activitys.H5Activity
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IBaseView
import de.baumann.browser.utils.StringUtil
import de.baumann.browser.utils.ViewUtil
import kotlinx.android.synthetic.main.activity_pack_url.*
import kotlinx.android.synthetic.main.include_tool_bar.*

/**
 *@author:junce
 *@date:2019/3/5 11:16
 *@discription: 添加红包广告地址
 */

class PackUrlActivity : BaseOdinActivity<IBaseView,BasePresenter<IBaseView>>() {

    override fun createPresenter(): BasePresenter<IBaseView>? {
        return null
    }

    override fun createView(): IBaseView? {
        return null
    }


    override fun getTitleText(): String {
        return getString(R.string.Importlink)
    }

    override fun getLayout(): Int {
        return R.layout.activity_pack_url
    }

    override fun initView() {
        initToolbar(commToolBar,commTitle)
        urlRoot.setPadding(0, ViewUtil.getStatusBarHeight(mContext), 0, 0)
        btnUrlPreview.setOnClickListener(object : View.OnClickListener {
            override fun onClick(p0: View?) {
                val url = getUrl()
                if (url.isEmpty()) {
                    return
                }
                H5Activity.startPreviewUrlActivity(mContext,url)
            }
        })
    }

    override fun initData() {
    }

    private fun getUrl(): String {
        val url = edUrl.text.toString()
        if (url.isEmpty()) {
            showShortToast(getString(R.string.input_product_link))
            return ""
        }

        if (!StringUtil.verifyUrl(url)) {
            showShortToast(getString(R.string.Please_enter_the_correct_link))
            return ""
        }

        return url
    }

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.menu_ok, menu)
        return super.onCreateOptionsMenu(menu)
    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        val url = getUrl()
        if (url.isEmpty()) {
            return false
        }
        intent.putExtra("url", url)
        setResult(Activity.RESULT_OK, intent)
        finish()
        return super.onOptionsItemSelected(item)
    }


}
